package com.atguigu.lease.app.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.bean.BrowsingHistory;
import com.atguigu.lease.app.service.BrowsingHistoryService;
import com.atguigu.lease.app.mapper.BrowsingHistoryMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 1
* @description 针对表【browsing_history(浏览历史)】的数据库操作Service实现
* @createDate 2025-09-28 11:32:26
*/
@Service
public class BrowsingHistoryServiceImpl extends ServiceImpl<BrowsingHistoryMapper, BrowsingHistory>
    implements BrowsingHistoryService{
    //springtask:定时任务  @EnableScheduling
    //springcache：缓存管理 @EnableCaching
    //spring async：异步执行 @EnableAsync  需要再启动类启用异步任务才能生效
    @Async
    @Override
    public void saveBrowsingHistory(Long userId, Long roomId) {
        try {
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        BrowsingHistory browsingHistory = new BrowsingHistory();
        browsingHistory.setUserId(userId);
        browsingHistory.setRoomId(roomId);
        browsingHistory.setBrowseTime(new Date());
        this.save(browsingHistory);

    }
}




